package com.wang.designpattern.factory.factorymethod.pizzastore.store;

import com.wang.designpattern.factory.factorymethod.pizzastore.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class OrderPizza {

    PizzaFactory pizzaFactory;

    Pizza pizza;

    public void setPizzaFactory(PizzaFactory pizzaFactory) {
        this.pizzaFactory = pizzaFactory;
    }
    // 构造器
    public OrderPizza() {

    }

    /**
     * 订购披萨
     * @return
     */
    public Pizza orderPizza() {
        // 订购pizza的类型
        String orderType = getType();
        pizza = pizzaFactory.orderPizza(orderType);
        if (null != pizza) {
            System.out.println("[" + pizza.getName() + "]订购成功！");
        }
        return pizza;
    }


    protected String getType() {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("请输入想订购的披萨类型：");
        String str  = null;
        try {
            str = bufferedReader.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }
}
